package functions.ems_claim;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import com.beans.AccountBean;
import com.beans.AdminUserBean;
import com.beans.CategoryBean;
import com.beans.ClaimBean;
import com.beans.CompanyBean;
import com.beans.EmployeeBankAccount;
import com.beans.VendorBean;
import com.crc.mam.BaseCase;
import coms.Constants;
import coms.JSONUtil;
import coms.TestDateString;
import frame.HttpHelper;
import functions.ems_base_data.MdOu;
import functions.ems_base_data.Vendor;

/**
 * 报账单
 * @author CHENHAILIAN6
 *
 */
public class Claim  extends BaseCase{
	
	JSONObject resultObject;
	String companyName;
	String deptName;
	
	public String getCompanyName() {
    return companyName;
  }

  public void setCompanyName(String companyName) {
    this.companyName = companyName;
  }

  public String getDeptName() {
    return deptName;
  }

  public void setDeptName(String deptName) {
    this.deptName = deptName;
  }

	private org.slf4j.Logger logger = LoggerFactory.getLogger(Claim.class);
	
	public ClaimBean getBean() {
		return bean;
	}

	public void setBean(ClaimBean bean) {
		this.bean = bean;
	}

	public String getMenuCategoryCode() {
		return menuCategoryCode;
	}

	public void setMenuCategoryCode(String menuCategoryCode) {
		this.menuCategoryCode = menuCategoryCode;
	}

	public String getMenuCategoryName() {
		return menuCategoryName;
	}

	public void setMenuCategoryName(String menuCategoryName) {
		this.menuCategoryName = menuCategoryName;
	}

	public AdminUserBean getLoginUserBean() {
		return loginUserBean;
	}

	public void setLoginUserBean(AdminUserBean loginUserBean) {
		this.loginUserBean = loginUserBean;
	}

	public ClaimBean getResponseClaimBean() {
		return responseClaimBean;
	}

	public void setResponseClaimBean(ClaimBean responseClaimBean) {
		this.responseClaimBean = responseClaimBean;
	}

	public ClaimBean getClaimHeadResBean() {
		return claimHeadResBean;
	}

	public void setClaimHeadResBean(ClaimBean claimHeadResBean) {
		this.claimHeadResBean = claimHeadResBean;
	}

	public HashMap<String, String> getHead() {
		return head;
	}

	public void setHead(HashMap<String, String> head) {
		this.head = head;
	}

	ClaimBean bean;
	
	String claimNo ;
	String claimId;
	String menuCategoryCode;
	String menuCategoryName;
	AdminUserBean loginUserBean ;
	ClaimBean responseClaimBean;
	ClaimBean claimHeadResBean;
    String lang;





	public String getLang() {
      return lang;
    }

    public void setLang(String lang) {
      this.lang = lang;
    }

  public Claim(AdminUserBean loginUser,String categoryCode,String menuCategoryName) {
		this.loginUserBean = loginUser;
		this.menuCategoryCode = categoryCode;
		this.menuCategoryName = menuCategoryName;
	}
	
	public Claim(String categoryCode,String menuCategoryName) {
      this.menuCategoryCode = categoryCode;
      this.menuCategoryName = menuCategoryName;
  } 
	public Claim() {
		// TODO Auto-generated constructor stub
	}

	public String getClaimId() {
		return claimId;
	}

	public void setClaimId(String claimId) {
		this.claimId = claimId;
	}

	

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	


	HashMap<String, String> head = new HashMap<String, String>();

	/**
	 * 保存报账单表头
	 * saveClaimHeadAndLineUrl="/ems-claim/claim/saveClaimHeadAndLine"
	 */
	public void saveTravelClaimHeadAndLine() {
		logger.info("保存报账单表头saveTravelClaimHeadAndLine  ----------------- start ------------");
		bean = new ClaimBean();
		String url = Constants.SAVE_CLAIM_HEAD_AND_LINE_URL;		
		claimNo = "";
		bean.setClaimNo(claimNo);
		String applEmpName = loginUserBean.getUserName();
		if (applEmpName == null) {
			applEmpName = "";
		}
		bean.setApplEmpName(applEmpName);
		String applOrgDeptName = loginUserBean.getDepartment();
		if (applOrgDeptName == null) {
			applOrgDeptName = "";
		}
		bean.setApplOrgDeptName(applOrgDeptName);
		String applOrgCompany = loginUserBean.getDepartment();
		if (applOrgCompany == null) {
			applOrgCompany = "";
		}
		bean.setApplOrgCompany(applOrgCompany);
		String applJobName = loginUserBean.getOccupation();
		if (applJobName == null) {
			applJobName = "";
		}
		bean.setApplJobName(applJobName);
		String applJobCode = loginUserBean.getOccupationCode();
		
		bean.setApplJobCode(applJobCode);
		String applEmpNo = loginUserBean.getEmpNo();
		if (applEmpNo == null) {
			applEmpNo = "";
		}
		bean.setApplEmpNo(applEmpNo);
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(currentTime);
		String applDate = dateString;
		String applEmail = loginUserBean.getEmail();
		if (applEmail == null) {
			applEmail = "";
		}
		bean.setApplEmail(applEmail);
		String applPhone = loginUserBean.getTelephone();
		if (applPhone == null) {
			applPhone = "";
		}
		bean.setApplPhone(applPhone);
		String isDaibao = loginUserBean.getSubstitute();
		if (isDaibao == null) {
			isDaibao = "";
		}
		bean.setIsDaibao(isDaibao);
		MdOu ou = new MdOu();
		ou.getCompanyByCompanyName(loginUserBean.getCompanyDesc());
		logger.info(ou.toString());
		CompanyBean myCompany = ou.getMyCompany();
		String ouCode = myCompany.getCompanycode();
		if (ouCode == null) {
			ouCode = "";
		}
		bean.setOuCode(ouCode);
		String ouName = myCompany.getCompanyName();
		if (ouName == null) {
			ouName = "";
		}
		bean.setOuName(ouName);
		String categoryCode = menuCategoryCode;
		if (categoryCode == null) {
			categoryCode = "";
		}
		bean.setCategoryCode(categoryCode);
		String categoryName = menuCategoryName;
		
		bean.setCategoryName(categoryName);
		String remark = "test";
		bean.setRemark(remark);
	    String jsonString = "";
	    String departmentId = loginUserBean.getDepartmentId();
	    String companyDesc = loginUserBean.getCompanyDesc();
		jsonString = "{" + "\"claimNo\":" + "\"" + claimNo + "\",\"applEmpName\":" + "\"" + applEmpName
				+ "\",\"applOrgDeptName\":" + "\"" + applOrgDeptName + "\",\"applJobName\":\"" + applJobName
				+ "\",\"applJobCode\":" + "\"" + applJobCode + "\",\"applEmpNo\":\"" + applEmpNo + "\",\"applDate\":"
				+ "\"" + applDate + "\",\"applEmail\":\"" + applEmail + "\",\"applPhone\":" + "\"" + applPhone
				+ "\",\"isDaibao\":" + isDaibao + ",\"ouCode\":" + "\"" + ouCode + "\",\"ouName\":\"" + ouName
				+ "\",\"categoryCode\":\"" + categoryCode
				+ "\",\"categoryName\":" + "\"" + categoryName + "\",\"remark\":\"" + remark + "\",\"currency\":\"CNY\","
				    + "\"paymentMode\":\"1\",\"attachNum\":\"\",\"accountingType\":\"3\",\"vendorCode\":\"\",\"vendorName\":\"\","
				    + "\"isChangeedAcceptReim\":0,\"hasContract\":false,\"applOrgDept\":\""+departmentId+"\",\"applOrgCompany\":\""+applOrgCompany+"\","
				    + "\"applOrgCompanyName\":\""+companyDesc+"\"}";
		logger.info("saveClaimHeadAndLine params ---  " + jsonString);

		try {
			result = HttpHelper.post(jsonString, url);
			logger.info("saveTravelClaimHeadAndLine--------" + result);
			status = HttpHelper.isOk;
			if(status) {
			try {
				JSONObject datas = new JSONObject(result);
				
				try {
					chaifenDatas(datas);
					remark = "[claimId="+claimId+",claimNo="+claimNo+"]";
				} catch (JSONException e) {
					e.printStackTrace();
					bean.setClaimId("");

				}
			} catch (Exception e) {
				e.printStackTrace();
				status = false;
			}
			}else {
			  JSONObject datas = new JSONObject(result);
			  remark = datas.getString("message");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			status = false;
			remark = "系统异常";
		}
		logger.info(" 返回结果  ------" + status);
		logger.info("保存报账单表头  ----------------- end ------------");
	}

	public void chaifenDatas(JSONObject datas) {
		responseClaimBean = new ClaimBean();

		try {

			responseClaimBean.setClaimNo(datas.getString("claimNo"));
		} catch (Exception e) {
			//e.printStackTrace();
			responseClaimBean.setClaimNo("");
		}

		try {
			responseClaimBean.setApplEmpName(datas.getString("applEmpName"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setApplEmpName("");
		}
		try {
			responseClaimBean.setApplOrgDeptName(datas.getString("applOrgDeptName"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setApplOrgDeptName("");
		}
		try {
			responseClaimBean.setApplOrgCompany(datas.getString("applOrgCompany"));
		} catch (JSONException e) {
			// e.printStackTrace();
			responseClaimBean.setApplOrgCompany("");
		}
		try {
			responseClaimBean.setApplJobName(datas.getString("applJobName"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setApplJobName("");
		}
		try {
			responseClaimBean.setApplJobCode(datas.getString("applJobCode"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setApplJobCode("");
		}
		try {
			responseClaimBean.setApplEmpNo(datas.getString("applEmpNo"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setApplEmpNo("");
		}
		try {
			responseClaimBean.setApplEmail(datas.getString("applEmail"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setApplEmail("");
		}
		try {
			responseClaimBean.setApplPhone(datas.getString("applPhone"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setApplPhone("");
		}
		try {
			responseClaimBean.setIsDaibao(datas.getString("isDaibao"));
		} catch (JSONException e) {
			// e.printStackTrace();
			responseClaimBean.setIsDaibao("");
		}
		try {
			responseClaimBean.setOuCode(datas.getString("ouCode"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setOuCode("");
		}
		try {
			responseClaimBean.setOuName(datas.getString("ouName"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setOuName("");
		}
		try {
			responseClaimBean.setClaimAmount(datas.getString("claimAmount"));

		} catch (JSONException e) {
			// e.printStackTrace();
			responseClaimBean.setClaimAmount("");
		}
		try {
			responseClaimBean.setCategoryCode(datas.getString("categoryCode"));

		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setCategoryCode("3001");
		}
		try {
			responseClaimBean.setCategoryName(datas.getString("categoryName"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setCategoryName("");
		}
		try {
			responseClaimBean.setPosition((String) datas.get("position"));
		} catch (Exception e) {
			//e.printStackTrace();
			responseClaimBean.setPosition("");
		}
		try {
			responseClaimBean.setIsAdditional(String.valueOf(datas.get("isAdditional")));
		} catch (Exception e) {
			//e.printStackTrace();
			responseClaimBean.setIsAdditional("");
		}
		try {
			responseClaimBean.setRemark(datas.getString("remark"));
		} catch (JSONException e) {
			//e.printStackTrace();
			responseClaimBean.setRemark("");
		}
		try {
			responseClaimBean.setClaimId(String.valueOf(datas.getInt("claimId")));
			this.claimId = String.valueOf(datas.getInt("claimId"));
		} catch (JSONException e) {
			//e.printStackTrace();
			this.claimId = "";
			responseClaimBean.setClaimId("");
		}
		System.out.println("responseBean ---" + responseClaimBean.toString());

	}

	/**
	 * 获取到保存后的表头信息
	 * getClaimHeadAndLineUrl="/ems-claim/claim/getClaimHeadAndLine"
	 */
	public void getClaimHeadAndLine() {
		logger.info("获取保存后的报账单表头 getClaimHeadAndLine ----------------- start ------------");
		String url = Constants.GET_CLAIM_HEAD_AND_LINE_URL;
		// System.out.println(url);
		String jsondata = "{\"claimId\":" + responseClaimBean.getClaimId() + "}";
		// System.out.println(jsondata);

		try {
			result = HttpHelper.post(jsondata, url);
			logger.info("getClaimHeadAndLine ---" + result);
			try {
				JSONObject datas = new JSONObject(result);
				claimHeadResBean = new ClaimBean();
				status = true;
				try {
					claimHeadResBean.setCategoryCode(datas.getString("categoryCode"));

				} catch (JSONException e) {
					e.printStackTrace();
					claimHeadResBean.setCategoryCode("");

				}
				try {
					claimHeadResBean.setOuCode(datas.getString("ouCode"));

				} catch (JSONException e) {
					e.printStackTrace();
					claimHeadResBean.setOuCode("HBJH0");

				}
			} catch (Exception e) {
				e.printStackTrace();
				status = false;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info("获取保存后的报账单表头 getClaimHeadAndLine ----------------- end ------------");
	}

	/**
	 * 保存员工借款的表单头信息
	 */
	public void loanSaveClaimHeadAndLine(EmployeeBankAccount employeeBankAccount,String categoryCode,String categoryName) {
	    
		ClaimBean loadClaimBean;
		logger.info(" 保存员工借款的表单头信息 ------- start -------------------");
		loadClaimBean = new ClaimBean();
		String url =Constants.SAVE_CLAIM_HEAD_AND_LINE_URL;
		
		String claimNo = "";
	
		loadClaimBean.setClaimNo(claimNo);
		String applEmpName = loginUserBean.getUserName();
		loadClaimBean.setApplEmpName(applEmpName);
		String applOrgDeptName = loginUserBean.getDepartment();
		this.deptName = applOrgDeptName;
		loadClaimBean.setApplOrgDeptName(applOrgDeptName);
		MdOu ou = new MdOu();
		ou.getCompanyByCompanyName(loginUserBean.getCompanyDesc());
        CompanyBean myCompany = ou.getMyCompany();
		String applOrgCompany = myCompany.getCompanycode();
		loadClaimBean.setApplOrgCompany(applOrgCompany);
		String applJobName = loginUserBean.getOccupation();
		loadClaimBean.setApplJobName(applJobName);
		String applJobCode = loginUserBean.getOccupationCode();
		loadClaimBean.setApplJobCode(applJobCode);
		String applEmpNo = loginUserBean.getEmpNo();
		loadClaimBean.setApplEmpNo(applEmpNo);
		Date currentTime = new Date();  
	    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
	    String dateString = formatter.format(currentTime);  
		String applDate = dateString;
		String applEmail =  loginUserBean.getEmail();
		loadClaimBean.setApplEmail(applEmail);
		String applPhone = loginUserBean.getTelephone();
		loadClaimBean.setApplPhone(applPhone);
		String ouCode = myCompany.getCompanycode();
		loadClaimBean.setOuCode(ouCode);
		String ouName = myCompany.getCompanyName();
		loadClaimBean.setOuName(ouName);
	    String departmentId = loginUserBean.getDepartmentId();
	 
	
		loadClaimBean.setCategoryCode(categoryCode);
		loadClaimBean.setCategoryName(categoryName);

		String remark = "test";
		
		loadClaimBean.setRemark(remark);
		
	    String claimId = "";
		loadClaimBean.setClaimId(claimId);
	    
	 //   System.out.println("save param --- "+loadClaimBean.toString());

		String jsonString = "{\"claimNo\":\"\",\"applEmpNo\":\""+applEmpNo+"\","
				+ "\"applEmpName\":\""+applEmpName+"\",\"applOrgDept\":\"\","
				+ "\"applOrgDeptName\":\""+applOrgDeptName+"\",\"applOrgCompany\":\""+applOrgCompany+"\","
				+ "\"applJobName\":\""+applJobName+"\",\"applJobCode\":\""+applJobCode+"\","
				+ "\"applDate\":\""+applDate+"\",\"ouCode\":\""+ouCode+"\",\"ouName\":\""+ouName+"\","
				+ "\"categoryCode\":\""+categoryCode+"\",\"currency\":\"CNY\",\"paymentMode\":\"\","
				+ "\"categoryName\":\""+categoryName+"\",\"applEmail\":\""+applEmail+"\",\"applPhone\":\""+applPhone+"\",\"attachNum\":\"0\",\"vendorCode\":\""+employeeBankAccount.getVendorCode()+"\","
				+ "\"vendorName\":\""+employeeBankAccount.getVendorName()+"\",\"vendorType\":\""+employeeBankAccount.getVendorType()+"\",\"capitalPlan\":\"\","
				+ "\"remark\":\"test\",\"loadType\":\"standbyFund\",\"claimId\":\"\"}";
	
		//System.out.println("save param --- "+jsonString);
		try {
			result = HttpHelper.post(jsonString, url);
			logger.info("saveClaimHeadAndLine--------"+ result);
			try {
				JSONObject datas = new JSONObject(result);
				try {
					claimId = String.valueOf(datas.get("claimId"));
					loadClaimBean.setClaimId(claimId);
					this.claimId = claimId;
				}catch(JSONException e) {
					e.printStackTrace();
				}
				status = true;
				try{
					/***
					 * 
					 */
				//	chaifenDatas(datas);
				 }catch(JSONException e) {
					 e.printStackTrace();
					 loadClaimBean.setClaimId("");
					 
			     }
			}catch(Exception e) {
				e.printStackTrace();
				status = false;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info(" 保存员工借款的表单头信息 ------- end -------------------");
	}
	
	/**
	 * 保存员工借款的表单头信息
	 */
	public void saveEmployeeLoanClaimHeadAndLine(CategoryBean categoryBean,AdminUserBean userBean,EmployeeBankAccount bankAccount,
	    AccountBean accountBean,CompanyBean ouCompany) {
	    String glDate = TestDateString.today();
	    String applDate = TestDateString.now();
		String params = "{\"categoryCode\":\""+categoryBean.getCategoryCode()+"\",\"categoryName\":\""+categoryBean.getCategoryName()+"\","
		    + "\"currency\":\"CNY\",\"paymentMode\":\"1\",\"attachNum\":\"0\",\"accountingType\":\"3\","
		    + "\"vendorCode\":\""+bankAccount.getVendorCode()+"\",\"vendorName\":\""+bankAccount.getVendorName()+"\","
		    + "\"loadType\":\"employee_loan\",\"glDate\":\""+glDate+"\","
		    + "\"ouCode\":\""+ouCompany.getCompanycode()+"\",\"ouName\":\""+ouCompany.getCompanyName()+"\","
		    + "\"vendorType\":\""+bankAccount.getVendorType()+"\",\"vendorAccountName\":\""+bankAccount.getVendorAccountName()+"\",\"vendorAccountNo\":\""+bankAccount.getVendorAccountNo()+"\","
		        + "\"vendorSiteCode\":\""+bankAccount.getVendorSiteId()+"\",\"vendorSiteName\":\""+bankAccount.getVendorSiteName()+"\",\"vendorBankCityCode\":\"\",\"vendorBankCityName\":\"\","
		    + "\"crAccountItemCode\":\""+accountBean.getAccountItemCode()+"\",\"crAccountItemName\":\""+accountBean.getAccountItemName()+"\",\"crChildAccountItemCode\":\""+accountBean.getChildAccountItemCode()+"\",\"crChildAccountItemName\":\""+accountBean.getChildAccountItemName()+"\","
		    + "\"remark\":\"test\",\"isChangeedAcceptReim\":0,\"hasContract\":false,\"claimNo\":\"\","
		    + "\"applEmpName\":\""+userBean.getUserName()+"\",\"applEmpNo\":\""+userBean.getEmpNo()+"\",\"applJobName\":\""+userBean.getOccupation()+"\",\"applJobCode\":\""+userBean.getOccupationCode()+"\","
		        + "\"applOrgDept\":\""+userBean.getDepartmentId()+"\",\"applOrgDeptName\":\""+userBean.getDepartment()+"\",\"applOrgCompany\":\""+userBean.getCompany()+"\","
		            + "\"applOrgCompanyName\":\""+userBean.getCompanyDesc()+"\",\"applEmail\":\""+userBean.getEmail()+"\",\"applPhone\":\""+userBean.getTelephone()+"\",\"applDate\":\""+applDate+"\",\"isDaibao\":false}";
		logger.info("employeeloanSaveClaimHeadAndLine params == " + params);			    
		String url =Constants.SAVE_CLAIM_HEAD_AND_LINE_URL;
		//System.out.println("save param --- "+jsonString);
		try {
			result = HttpHelper.post(params, url);
			logger.info("employeeloanSaveClaimHeadAndLine--------"+ result);
			status = HttpHelper.isOk;
			if(status) {
			  try {
				
				  JSONObject datas = new JSONObject(result);
					this.claimId = String.valueOf(datas.get("claimId"));
					this.claimNo = datas.getString("claimNo");
					this.lang = datas.getString("lang");
				    remark = "[claimId="+this.claimId+",claimNo="+this.claimNo+"]";
				}catch(JSONException e) {
					e.printStackTrace();
					remark = "JSON解析错误";
				}
			}else {
			  try {
			    JSONObject datas = new JSONObject(result);
			    remark = datas.getString("message");
			  }catch(JSONException e) {
			    e.printStackTrace();
			    remark = "JSON解析错误";
			  }
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			logger.info(e.getMessage());
			remark = "系统异常";
			status = false;
		}
		logger.info(" 保存员工借款的表单头信息 ------- end -------------------");
	}

	public String getClaimNo() {
		return claimNo;
	}

	public void setClaimNo(String claimNo) {
		this.claimNo = claimNo;
	}

	
	/**
	 * 供应商预付款
	 */
	public void gongyingshangSaveClaimHeadAndLine(VendorBean vendorBean) {
		
		//String subCategoryCode = "9004166";
		
		ClaimBean loadClaimBean;
		logger.info(" 保存员工借款的表单头信息 ------- start -------------------");
		loadClaimBean = new ClaimBean();
		String url =Constants.SAVE_CLAIM_HEAD_AND_LINE_URL;
		
		String claimNo = "";
	
		loadClaimBean.setClaimNo(claimNo);
		String applEmpName = loginUserBean.getUserName();
		loadClaimBean.setApplEmpName(applEmpName);
		String applOrgDeptName = loginUserBean.getDepartment();
		this.deptName = applOrgDeptName;
		
		loadClaimBean.setApplOrgDeptName(applOrgDeptName);
		String applOrgCompany = loginUserBean.getCompany();
		this.companyName = applOrgCompany;
		loadClaimBean.setApplOrgCompany(applOrgCompany);
		String applJobName = loginUserBean.getOccupation();
		loadClaimBean.setApplJobName(applJobName);
		String applJobCode = "";
		
		loadClaimBean.setApplJobCode(applJobCode);
		String applEmpNo = loginUserBean.getEmpNo();
		loadClaimBean.setApplEmpNo(applEmpNo);
		Date currentTime = new Date();  
	    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
	    String dateString = formatter.format(currentTime);  
		String applDate = dateString;
		String applEmail =  loginUserBean.getEmail();
		loadClaimBean.setApplEmail(applEmail);
		String applPhone = loginUserBean.getTelephone();
		loadClaimBean.setApplPhone(applPhone);
		MdOu ou = new MdOu();
		ou.getCompanyByCompanyName(loginUserBean.getCompanyDesc());
        CompanyBean myCompany = ou.getMyCompany();
		String ouCode = myCompany.getCompanycode();
		loadClaimBean.setOuCode(ouCode);
		String ouName = myCompany.getCompanyName();
		loadClaimBean.setOuName(ouName);
	


		String remark = "test";
		
		loadClaimBean.setRemark(remark);
		
	    String claimId = "";
		loadClaimBean.setClaimId(claimId);
	    
	 //   System.out.println("save param --- "+loadClaimBean.toString());

	/*	String jsonString = "{\"claimNo\":\"\",\"applEmpNo\":\""+applEmpNo+"\","
				+ "\"applEmpName\":\""+applEmpName+"\",\"applOrgDept\":\"\","
				+ "\"applOrgDeptName\":\""+applOrgDeptName+"\",\"applOrgCompany\":\""+applOrgCompany+"\","
				+ "\"applJobName\":\""+applJobName+"\",\"applJobCode\":\""+applJobCode+"\","
				+ "\"applDate\":\""+applDate+"\",\"ouCode\":\""+ouCode+"\",\"ouName\":\""+ouName+"\","
				+ "\"categoryCode\":\""+categoryCode+"\",\"currency\":\"CNY\",\"paymentMode\":\"1\","
				+ "\"categoryName\":\""+categoryName+"\",\"applEmail\":\""+applEmail+"\",\"applPhone\":\""+applPhone+"\",\"attachNum\":\"0\",\"vendorCode\":\""+vendorBean.getVendorCode()+"\","
				+ "\"vendorName\":\""+vendorBean.getVendorName()+"\",\"vendorType\":\""+vendorBean.getVendorType()+"\",\"capitalPlan\":\"\","
				+ "\"remark\":\"test\",\"loadType\":\"projectLoan\",\"claimId\":\"\",\"certificateNo\":\"\",\"glDate\":\"\"}";
	*/
		//System.out.println("save param --- "+jsonString);
		try {
			result = HttpHelper.post("", url);
			logger.info("saveClaimHeadAndLine--------"+ result);
			try {
				JSONObject datas = new JSONObject(result);
				try {
					chaifenDatas(datas);
					claimId = String.valueOf(datas.get("claimId"));
					loadClaimBean.setClaimId(claimId);
					this.claimId = claimId;
				}catch(JSONException e) {
					e.printStackTrace();
				}
				status = true;
				try{
					/***
					 * 
					 */
				//	chaifenDatas(datas);
				 }catch(JSONException e) {
					 e.printStackTrace();
					 responseClaimBean.setClaimId("");
					 
			     }
			}catch(Exception e) {
				e.printStackTrace();
				status = false;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info(" 保存员工借款的表单头信息 ------- end -------------------");
	}
	
	public void payRequstSaveClaimHeadAndLine(Map<Object, Object> paramMap) {
		String ouCode = (String) paramMap.get("ouCode");
		if(ouCode == null) {
			ouCode = "";
		}
		String ouName = (String)paramMap.get("ouName");
		if(ouName == null) {
			ouName = "";
		}
		String categoryCode = (String)paramMap.get("categoryCode");
		if(categoryCode == null) {
			categoryCode = "";
		}
		
		String categoryName = (String)paramMap.get("categoryName");
		if(categoryName == null) {
			categoryName = "";
		}
		String rootCategoryCode = (String)paramMap.get("rootCategoryCode");
		if(rootCategoryCode == null) {
			rootCategoryCode = "";
		}
		String rootCategoryName = (String)paramMap.get("rootCategoryName");
		if(rootCategoryName == null) {
			rootCategoryName = "";
		}
		JSONArray payLineJsonData = (JSONArray) paramMap.get("payLineJsonData");
		  String payRequestLinesStrings = "";
	      for(int i = 0;i<payLineJsonData.length();i++) {
	        if(payRequestLinesStrings.equals("")) {
	          payRequestLinesStrings = "[" + JSONUtil.jsonToString(payLineJsonData.getJSONObject(i));
	        }else {
	          payRequestLinesStrings = "," + JSONUtil.jsonToString(payLineJsonData.getJSONObject(i));
	        }
	      }
	      payRequestLinesStrings = payRequestLinesStrings + "]";
	      logger.info("payRequestLinesStrings" +payRequestLinesStrings );
	      
		String jsonString = "{\"ouCode\":\""+ouCode+"\",\"ouName\":\""+ouName+"\",\"categoryCode\":"+categoryCode+","
				+ "\"categoryName\":\""+categoryName+"\",\"rootCategoryCode\":"+rootCategoryCode+",\"rootCategoryName\":\""+rootCategoryName+"\","
				+ "\"payLineJsonData\":\""+payRequestLinesStrings+"\"}";
		logger.info("payRequstSaveClaimHeadAndLine param ----" + jsonString);
		String url =Constants.SAVE_CLAIM_HEAD_AND_LINE_URL;
		try {
			result = HttpHelper.post(jsonString, url);
			status = HttpHelper.isOk;
			logger.info("payRequstSaveClaimHeadAndLine--------"+ result);
			if(status) {
				try {
					JSONObject datas = new JSONObject(result);
					try {
						//chaifenDatas(datas);
						resultObject = datas;
						claimId = String.valueOf(datas.get("claimId"));
						//	loadClaimBean.setClaimId(claimId);				
					}catch(JSONException e) {
						e.printStackTrace();
					}
					status = true;
					try{
					/***
					 * 
					 */
						//	chaifenDatas(datas);
					}catch(JSONException e) {
						e.printStackTrace();
						responseClaimBean.setClaimId("");
					 
					}
				}catch(Exception e) {
					e.printStackTrace();
					status = false;
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info(" 返回结果  ------" + status);
		logger.info(" 保存付款申请的表单头信息 ------- end -------------------");
	}
	
	public void payClaimInfoSaveClaimHeadAndLine(Map<Object, Object> paramMap) {
	  String ouCode = (String) paramMap.get("ouCode");
      if(ouCode == null) {
          ouCode = "";
      }
      String ouName = (String)paramMap.get("ouName");
      if(ouName == null) {
          ouName = "";
      }
      String categoryCode = (String)paramMap.get("categoryCode");
      if(categoryCode == null) {
          categoryCode = "";
      }
      
      String categoryName = (String)paramMap.get("categoryName");
      if(categoryName == null) {
          categoryName = "";
      }
      String rootCategoryCode = (String)paramMap.get("rootCategoryCode");
      if(rootCategoryCode == null) {
          rootCategoryCode = "";
      }
      String rootCategoryName = (String)paramMap.get("rootCategoryName");
      if(rootCategoryName == null) {
          rootCategoryName = "";
      }
      String attachNum = (String)paramMap.get("attachNum");
      if(attachNum == null) {
        attachNum = "1";
      }
      String remark = (String) paramMap.get("remark");
      if(remark == null) {
        remark = "付款申请保存";
      }
      String currency = (String) paramMap.get("currency");
      if(currency == null) {
        currency = "CNY";
      }
      String buCode = (String) paramMap.get("buCode");
      if(buCode == null) {
        buCode = "B29";
      }
      String claimId = (String) paramMap.get("claimId");
      if(claimId == null) {
        try {
          throw new Exception("未创建该付款计划对应的付款申请单行");
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } 
      JSONArray payRequestLines = (JSONArray) paramMap.get("payRequestLines");
      for(int i=0;i<payRequestLines.length();i++) {
        JSONObject object = payRequestLines.getJSONObject(i);
        if(object.get("vendorAccountNo") == null) {
          Vendor vendor = new Vendor();
          vendor.findPagedVendorList("");
        }
        
      }
      /*String payRequestLinesStrings = "";
      for(int i = 0;i<payRequestLines.length();i++) {
        if(payRequestLinesStrings.equals("")) {
          payRequestLinesStrings = "[" + JSONUtil.jsonToString(payRequestLines.getJSONObject(i));
        }else {
          payRequestLinesStrings = "," + JSONUtil.jsonToString(payRequestLines.getJSONObject(i));
        }
      }
      payRequestLinesStrings = payRequestLinesStrings + "]";
      */
      logger.info("payRequestLinesStrings" +payRequestLines.toString() );
      String jsonString = "{\"claimId\":"+claimId+",\"remark\":\""+remark+"\",\"attachNum\":\""+attachNum+"\",\"buCode\":\""+buCode+"\",\"currency\":\""+currency+"\",\"ouCode\":\""+ouCode+"\",\"ouName\":\""+ouName+"\",\"categoryCode\":"+categoryCode+","
              + "\"categoryName\":\""+categoryName+"\",\"rootCategoryCode\":"+rootCategoryCode+",\"rootCategoryName\":\""+rootCategoryName+"\","
              + "\"payRequestLines\":"+payRequestLines.toString()+"}";
      logger.info("payClaimInfoSaveClaimHeadAndLine params ----" + jsonString);
      String url =Constants.SAVE_CLAIM_HEAD_AND_LINE_URL;
      try {
          result = HttpHelper.post(jsonString, url);
          status = HttpHelper.isOk;
          logger.info("saveClaimHeadAndLine--------"+ result);
          if(status) {
              try {
                  JSONObject datas = new JSONObject(result);
                  try {
                      chaifenDatas(datas);
                      resultObject = datas;
                      claimId = String.valueOf(datas.get("claimId"));
                      //  loadClaimBean.setClaimId(claimId);              
                  }catch(JSONException e) {
                      e.printStackTrace();
                  }
                  status = true;
                  try{
                  /***
                   * 
                   */
                      //  chaifenDatas(datas);
                  }catch(JSONException e) {
                      e.printStackTrace();
                      responseClaimBean.setClaimId("");
                   
                  }
              }catch(Exception e) {
                  e.printStackTrace();
                  status = false;
              }
          }
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      logger.info(" 返回结果  ------" + status);
      logger.info(" 保存员工借款的表单头信息 ------- end -------------------");
	}
	
	public AdminUserBean findCurrentEmployee() {
	  logger.info("获取当前员工信息---- start --------------");
	  AdminUserBean bean = null;
	  String url = Constants.FIND_CURRENT_EMPLOYEE_URL;
	  try {
	    result = HttpHelper.get(null, url);
	    logger.info("findCurrentEmployee---- "+result);
	    status = HttpHelper.isOk;
	    if(status) {
	      try {
	        JSONObject object = new JSONObject(result);
	        String applyDate = "";
	        if(object.get("applyDate")!=null) {
	          applyDate = object.getString("applyDate");
	        }
	        String businessLine = "";
            if(object.get("businessLine")!=null) {
              businessLine = object.getString("businessLine");
            }
            String businessUnit = "";
            if(object.get("businessUnit")!=null) {
              businessUnit = object.getString("businessUnit");
            }
            String company = "";
            if(object.get("company")!=null) {
              company = object.getString("company");
            }
            String companyDesc = "";
            if(object.get("companyDesc")!=null) {
              companyDesc = object.getString("companyDesc");
            }
            String department = "";
            if(object.get("department")!=null) {
              department = object.getString("department");
            }
            String departmentId = "";
            if(object.get("departmentId")!=null) {
              departmentId = object.getString("departmentId");
            }
            String email = "";
            if(object.get("email")!=null) {
              email = object.getString("email");
            }
            String empNo = "";
            if(object.get("empNo")!=null) {
              empNo = object.getString("empNo");
            }
            String financeBusinessUnit = "";
            if(object.get("financeBusinessUnit")!=null) {
              financeBusinessUnit = object.getString("financeBusinessUnit");
            }
            String financeCompany = "";
            if(object.get("financeCompany")!=null) {
              financeCompany = object.getString("financeCompany");
            }
            String occupation = "";
            if(object.get("occupation")!=null) {
              occupation = object.getString("occupation");
            }
            String occupationCode = "";
            if(object.get("occupationCode")!=null) {
              occupationCode = object.getString("occupationCode");
            }
            String substitute = "";
            if(object.get("substitute")!=null) {
              substitute = String.valueOf(object.getBoolean("substitute"));
            }
            String telephone = "";
            if(object.get("telephone")!=null) {
              telephone = object.getString("telephone");
            }
            String userCode = "";
            if(object.get("userCode")!=null) {
              userCode = object.getString("userCode");
            }
            String userName = "";
            if(object.get("userName")!=null) {
              userName = object.getString("userName");
            }
            bean = new AdminUserBean(occupation, companyDesc, departmentId,telephone,
                empNo, userName, substitute, userCode,occupationCode,
                company, applyDate, department, email, businessLine,
                 businessUnit,  financeBusinessUnit, financeCompany);
            logger.info(bean.toString());
	      }catch(JSONException e) {
	        e.printStackTrace();
	        remark = "JSON 解析异常";
	      }
	    }else {
	      try {
            JSONObject object = new JSONObject(result);
            remark = object.getString("message");
          }catch(JSONException e) {
            e.printStackTrace();
          }
	      status= false;
	      
	    }
	  }catch(Exception e) {
	    e.printStackTrace();
	    status = false;
	    remark = "系统异常";
	  }
	  logger.info(" 返回结果  ------" + status);
	  return bean;
	}
}
